// Check if a number is Unique
// This tests if a number is Unique for about 252 is not Unique since we have a repeating 2 while 658 is
// The program works simple by breaking down the number and checking if they are found in a vector.
// If the number is found then we set a flag of false otherwise true is returned.
// By Ben 24/10/2018

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

using std::cout;
using std::endl;

bool IsIntUnique(int number){
	int i = 0;
	int digit = 0;
	bool flag = true;
	int tmp = number;
	vector<int>digits;
	
	while (tmp > 0){
		//Get single digit
		digit = tmp % 10;
		//Keep dividing the number by 10
		tmp /= 10;
		//Check if the digit is already in the vector.
		if (std::find(digits.begin(), digits.end(), digit) != digits.end()){
			flag = false;
			break;
		}
		else{
			//Add digit to the vector.
			digits.push_back(digit);
		}
	}
	//Clear up.
	digits.clear();

	return flag;
}

int main()
{
	std::cout << "Is 5624 Unique " << IsIntUnique(5624) << endl;
	std::cout << "Is 255 Unique " << IsIntUnique(255) << endl;
	std::cout << "Is 65535 Unique " << IsIntUnique(65535) << endl;
	std::cout << "Is 9185 Unique " << IsIntUnique(9185) << endl;
	system("pause");
	return 0;
}
